package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.ShoppingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class ShoppingController {
    @Autowired
    ShoppingService shoppingService;
    @RequestMapping("/findCun")
    public Object findCun(){
        List<Map> list = shoppingService.findCun();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",list.get(0).get("total"));
        return jsonObject;
    }
    @RequestMapping("/findShen")
    public Object findShen(){
        List<Map> list = shoppingService.findShen();
        //1
        JSONObject jsonObject = new JSONObject();
        //1.1
        jsonObject.put("status",0);
        //1.2
        jsonObject.put("msg","");
        //1.3
        JSONObject dataObject = new JSONObject();
        //1.3.1
        JSONArray mapArray = new JSONArray();
        for (Map map : list) {
            JSONObject mapObject = new JSONObject();
            mapObject.put("name",map.get("name"));
            mapObject.put("value",map.get("total"));
            mapArray.add(mapObject);
        }
        dataObject.put("mapData",mapArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }
    @RequestMapping("/findBtu")
    public Object findBtu(){
        List<Map> list = shoppingService.findBtu();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray dataArray = new JSONArray();
        for (Map map : list) {
            JSONObject dataObject = new JSONObject();
            dataObject.put("name",map.get("name"));
            dataObject.put("value",map.get("zb"));
            dataArray.add(dataObject);
        }
        jsonObject.put("data",dataArray);
        return jsonObject;
    }
    @RequestMapping("/findZhu")
    public Object findZhu(){
        List<Map> list = shoppingService.findZhu();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray xArray = new JSONArray();
        for (Map map : list) {
            xArray.add(map.get("name"));
        }
        dataObject.put("categories",xArray);
        JSONArray yArray = new JSONArray();
        JSONObject yObject = new JSONObject();
        yObject.put("name","各个完运次数");
        JSONArray dataArray = new JSONArray();
        yObject.put("data",dataArray);
        for (Map map : list) {
            dataArray.add(map.get("uID"));
        }
        yArray.add(yObject);
        dataObject.put("series",yArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }


}
